﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTcpSocket>
#include <QLabel>
#include <QAudio>
#include <QAudioFormat>
#include <QAudioInput>
#include <QAudioOutput>
#include <QIODevice>
#include <QFile>
#include <QFileDialog>
#include <QUdpSocket>
#include "audiothread.h"
#include "audiorecthread.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
private:
    QTcpSocket  *tcpClient;  //socket
//    QTcpSocket  *file_tcpClient;  //socket
    QLabel  *LabSocketState;  //状态栏显示标签

    QString getLocalIP();//获取本机IP地址
protected:
    void    closeEvent(QCloseEvent *event);

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    QFile *file_voice;
    QFile *file;
    QFile *file_voice_receive;
    QFile *file_receive;
    QFile *file_picture_receive;
//    qint64 m_totalBytes,m_bytesWritten,m_bytesToWrite,m_payloadSize;
    qint64 fileBytes, sentBytes, restBytes;
//    QByteArray m_outBlock;
    QString aFile_str;
    QByteArray receivedData;
    int packetLength ;
    int receive_fileName_length;
    qint64 receive_fileSize;
    qint64 data_length_per_sum;
    QString AddIp;

private slots:
//自定义槽函数
    void    onConnected();
    void    onDisconnected();
    void    onSocketStateChange(QAbstractSocket::SocketState socketState);
//    void    onSocketReadyRead();//读取socket传入的数据
//
    void on_actConnect_triggered();

    void on_actDisconnect_triggered();

    void on_actClear_triggered();

    void on_btnSend_clicked();

    void on_btn_voice_pressed();

    void on_btn_voice_released();

    void record_stop();

    void on_btn_voice_speak_clicked();

    void on_btn_file_clicked();

    void on_btn_picture_clicked();

    void onfileSocketReadyRead();

    void deal_with_file(QByteArray fileserreceive_per);

    void on_btn_telephone_clicked();

    //语音对讲
    void MicroPhoneonReadyRead();
    void RecreadyReadSlot();
//    QString AddIPChange();

private:
    Ui::MainWindow *ui;
    QFile destinationFile;
    QAudioInput *voiceInput;//音频输入设备
    void file_0x42();
    void file_0x43();
    void file_0x44();
    void file_0x45();
    void voice_file_0x31();
    void voice_file_0x32();
    void voice_file_0x33();
    void voice_file_0x34();
    void voice_file_0x35();
    QUdpSocket *udpSocket;//用于音频信号的发送
    AudioThread *myAudio;
    AudioRecThread *myAudioRec;
};

#endif // MAINWINDOW_H
